<!-- Add Modal //-->
<div id="addModal" class="reveal-modal small tmbModal" data-reveal>
	<p class="p-modal">Tambah pengaturan subsidi</p>
	<div class="isi-modal">
	<?php 
		echo form_open('a_subsidi/save', array('id' => 'SaveAturSubsidi')); 
	?>
		<div class="row">
		
			<div class="col-md-12">				  
			<input type="text" name="nama_subsidi" class="form-control form-elba input-sm clearable" placeholder="Nama subsidi"/><br/>	
			<select name="id_m_instansi" class="form-control form-elba input-sm" <?php if(count($list_i)<1){echo "disabled";}?>>
				<?php 
					if(count($list_i)>0){
						foreach ($list_i as $row_i){ ?>
					<option value="<?php echo $row_i->id_m_instansi; ?>"><?php echo $row_i->instansi; ?></option>
				<?php 
						}
					}else{ 
				?>
					<option value="null">Tidak ada data</option>
				<?php
					}
				?>
			</select><br/>
			<input type="text" name="total_subsidi" class="form-control form-elba input-sm clearable" placeholder="Besar subsidi"/><br/>
			<input type="text" id="tgl" name="tgl_terima" class="form-control form-elba input-sm inputmask-cal clearable" readonly placeholder="Tanggal terima"/><br/>
			<textarea name="ket" class="form-control form-elba input-sm bfh-phone clearable" placeholder="Keterangan"></textarea><br/><br/>	
			</div>
		</div><br/><br/>

		<span id="loadingAdd" style="display:none;">Sedang memproses..</span>
		<span id="errorAdd" style="display:none;color:red;">Ma'af, gagal menambahkan data</span>
		
		<span class="pull-right">
			<button type="submit" id="saveButton" class="btn btn-xs tmb-utama"> Simpan</button> 
			<button class="btn tmb-kedua close-reveal-modal close-modal"> Batal</button>
		</span>
	
	<?php 
		echo form_close();
	?>	
	</div>
 </div>
<!-- End Add Modal //-->

<!-- Delete Modal //-->
<div id="delModal" class="reveal-modal tiny" data-reveal>
	<p class="p-modal">
	<span id="hpid" class="hpid var-modal" style="display:none;"></span>
	Yakin ingin menghapus pemberian <span class="nama var-modal"></span> dari <span class="2nd var-modal"></span> sebesar Rp <span class="3rd var-modal"></span>?</p><br/><br/>
	<span id="loadingDel" style="display:none;">Sedang memproses..</span>
	<span id="errorDel" style="display:none;color:red;">Ma'af, gagal dihapus</span>
	<span class="pull-right">
		<button class="deleteUrl btn btn-xs tmb-utama" id="hapusAturSubsidi"> Yakin</button> 
		<button class="btn tmb-kedua close-reveal-modal close-modal"> Tidak</button>
	</span>
</div>
<!-- End Delete Modal //-->

<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default kotakwidget">
			<div class="panel-heading kepalakotakwidget">
				Pengaturan Penerimaan Subsidi dari Instansi
				<span class="pull-right">
					<button data-reveal-id="addModal" data-reveal class="btn btn-sm tmb-tambah tmb-utama"><i class="fa fa-plus"></i> Tambah</button>
				</span>				
			</div>
				
				<div class="panel-body">
					<div class="row">
						<div class="col-md-12">
							<div id="contentAturSubsidi">
							<table class="table table-condensed" id="th_ajaran">
							  <thead>
								<tr>
									<th>#</th>
									<th>Nama Subsidi</th>
									<th>Instansi Pemberi</th>
									<th>Besar Subsidi</th>
									<th>Tgl. Terima</th>
									<th>Keterangan</th>								
								</tr>
							  </thead>
							  <tbody>
								<?php 
									if(count($list)>0){
										$i = 1; 
										foreach ($list as $row) {
								?>
								<tr class="hover kursor">
									<td width="30"><?php echo $i++ ?></td>
									<td><?php echo $row->nama_subsidi; ?></td>
									<td><?php echo $row->instansi; ?></td>
									<td><?php echo formatRupiahTabel($row->total_subsidi); ?></td>
									<td><?php echo hijriahSimple($row->tgl_terima);?></td>
									<td>
										<?php echo $row->ket; ?>
										<a class="editorLink pull-right" data-reveal-id="delModal" nama="<?php echo $row->nama_subsidi; ?>" 2nd="<?php echo $row->instansi; ?>" 3rd="<?php echo formatRupiah($row->total_subsidi); ?>" hpid="<?php echo $row->id_a_subsidi;?>" data-reveal><span class="glyphicon glyphicon-floppy-remove"></span></a>
									</td> 
								</tr>
								<?php
										}
									}else{
								?>
								<tr>
									<td colspan="6"><center>Belum ada pengaturan subsidi</center></td>
								</tr>
								<?php
									}
								?>
							  </tbody>
							</table>
							</div>
						</div>
					</div>
				</div>
		</div>
	</div>	
</div>
<!-- /#page-wrapper -->
<script>
// Auto Focus Input Form
$(document).on('opened', '[data-reveal]', function () {
	$('.clearable').first().focus();
});
// Datepicker
$('#tgl').datepicker({
	format: "dd/mm/yyyy",
    language: "id",
    todayHighlight: true
});
// Save
$('#SaveAturSubsidi').bind('submit', function(event) {
	var link = $(this).attr('action');
	$.ajax({
		url: link,
		type: "POST",
		data: $(this).serialize(),
		cache: false,
		beforeSend: function(){
			$('#loadingAdd').show();
			$('#errorAdd').hide();
		},          
		success: function() {
			var $container = $("#contentAturSubsidi");
			$container.load("<?php echo site_url(); ?>a_subsidi/refresh");
			
			$('#loadingAdd').hide();
			$('#addModal').foundation('reveal', 'close');
		},
		error:function(){
			$('#loadingAdd').hide();
			$('#errorAdd').show();
		}
	});
	return false; // dont post it automatically
});
// Delete
$("#hapusAturSubsidi").on("click", function(){
var id_a_subsidi= $("#hpid").text();
	$.ajax({
		type: "POST",
		data: "id_a_subsidi="+id_a_subsidi,
		url : "<?php echo site_url(); ?>a_subsidi/delete",				
		cache: false,
		beforeSend: function(){
			$('#loadingDel').show();
			$('#errorDel').hide();
		}, 
		success: function(){
			var $container = $("#contentAturSubsidi");
			$container.load("<?php echo site_url(); ?>a_subsidi/refresh");
			
			$('#loadingDel').hide();
			$('#delModal').foundation('reveal', 'close');					
		}, 
		error:function(){
			$('#loadingDel').hide();
			$('#errorDel').show();
		}
	});
	return false; 
});
</script>